package com.ruoyi.energy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.energy.domain.TcCar;
import com.ruoyi.energy.domain.TcOut;
import com.ruoyi.energy.domain.vo.CarDayQualityVO;
import com.ruoyi.energy.domain.vo.TcCarWXVO;
import com.ruoyi.energy.domain.vo.TcOutWXVO;
import com.ruoyi.energy.mapper.TcOutMapper;
import com.ruoyi.energy.service.ITcOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 出场回调Service业务层处理
 *
 * @author cjie
 * @date 2021-11-30
 */
@Service
public class TcOutServiceImpl implements ITcOutService {
    @Autowired
    private TcOutMapper tcOutMapper;

    /**
     * 查询出场回调
     *
     * @param parkId 出场回调ID
     * @return 出场回调
     */
    @Override
    public TcOut selectTcOutById(String parkId) {
        return tcOutMapper.selectTcOutById(parkId);
    }

    /**
     * 查询出场回调列表
     *
     * @param tcOut 出场回调
     * @return 出场回调
     */
    @Override
    public List<TcOut> selectTcOutList(TcOut tcOut) {
        return tcOutMapper.selectTcOutList(tcOut);
    }

    /**
     * 新增出场回调
     *
     * @param tcOut 出场回调
     * @return 结果
     */
    @Override
    public int insertTcOut(TcOut tcOut) {
        tcOut.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        tcOut.setCreateTime(DateUtils.getNowDate());
        tcOut.setCreateBy(SecurityUtils.getUsername());
        return tcOutMapper.insertTcOut(tcOut);
    }

    /**
     * 修改出场回调
     *
     * @param tcOut 出场回调
     * @return 结果
     */
    @Override
    public int updateTcOut(TcOut tcOut) {
        return tcOutMapper.updateTcOut(tcOut);
    }

    /**
     * 批量删除出场回调
     *
     * @param parkIds 需要删除的出场回调ID
     * @return 结果
     */
    @Override
    public int deleteTcOutByIds(String[] parkIds) {
        return tcOutMapper.deleteTcOutByIds(parkIds);
    }

    /**
     * 删除出场回调信息
     *
     * @param parkId 出场回调ID
     * @return 结果
     */
    @Override
    public int deleteTcOutById(String parkId) {
        return tcOutMapper.deleteTcOutById(parkId);
    }

    @Override
    public List<TcOutWXVO> selectTcOutWXVOList(TcOutWXVO tcOut) {
        TcOut search = BeanUtil.toBean(tcOut,TcOut.class);
        List<TcOut> tcOuts = tcOutMapper.selectTcOutList(search);
        List<TcOutWXVO> results = new ArrayList<>(tcOuts.size());
        for(TcOut tout:tcOuts){
            results.add(BeanUtil.toBean(tout,TcOutWXVO.class));
        }
        return results;
    }

    @Override
    public TcOut selectTcOutByAccessInId(String accessInId) {
        return tcOutMapper.selectTcOutByAccessInId(accessInId);
    }

    @Override
    public int deleteTcOutByAccessIdIn(String accessId) {
        return tcOutMapper.deleteTcOutByAccessIdIn(accessId);
    }

    @Override
    public CarDayQualityVO selectDayQuality() {
        return tcOutMapper.selectDayQuality();
    }
}
